iT邦幫忙

0

30天 Leetcode挑戰_Day 6

  • 分享至 

  • xImage
  •  

今天的題目蠻簡單的
今日耗時:7mins

  1. Contains DuplicateGiven
    Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
class Solution {
public:
    bool containsDuplicate(vector<int>& nums){
        int n=nums.size();
        sort(nums.begin(),nums.end());
        for(int i=0;i<n-1;i++){
            if(nums[i]==(nums[i+1])){
                return true;
            }  
        }
        return false;
    }
};

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言